package com.lagou.homework134;

import java.util.LinkedList;
import java.util.List;


public class StudentInfoManager {

    private static List<Student> list = new LinkedList<>();

    public static void add(Student stu) {
        list.add(stu);
        System.out.println("添加成功！");
        findAll();
    }

    public static Student find(String name) {
        for (Student stu : list) {
            if (name.equals(stu.getName()))
                return stu;
        }
        System.out.println("不存在" + name + "这个学生");
        return null;
    }

    public static void findAll() {
        for (int i = 0; i < list.size(); i++)
            System.out.println(i + " : " + list.get(i));
//        System.out.println();
    }

    public static void update(int index, String name) {
        Student stu = list.get(index);
        System.out.println("修改前：" + stu);
        stu.setName(name);
        list.set(index, stu);
        System.out.println("修改后：" + list.get(index));
//        initUI();
    }

    public static void delete(String name) {
        Student stu = find(name);
        if (stu != null)
            list.remove(stu);
        findAll();
    }

}
